package com.salton123.ui.base

import android.app.Activity
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.salton123.arch.view.IImmersionView
import com.salton123.arch.view.IMultiStatusView
import com.salton123.arch.view.ITitleBarView
import com.salton123.feature.ImmersionFeature
import com.salton123.feature.MultiStatusFeature
import com.salton123.feature.TitleBarViewFeature
import com.wuhenzhizao.titlebar.widget.CommonTitleBar

/**
 * User: newSalton@outlook.com
 * Date: 2019/12/12 15:59
 * ModifyTime: 15:59
 * Description:
 */
abstract class BaseActivity(
    private val multiStatusFeature: MultiStatusFeature = MultiStatusFeature(),
    private val immersionFeature: ImmersionFeature = ImmersionFeature()
) : LifeDelegateActivity(),
    ITitleBarView,
    IMultiStatusView by multiStatusFeature,
    IImmersionView by immersionFeature {
    private val titleBarFeature = TitleBarViewFeature()

    override fun initLogic() {
        if (enableImmersionBar()) {
            immersionFeature.with(this)
            addFeature(immersionFeature)
            dardFont()
        }
        if (enableMultiStatus()) {
            multiStatusFeature.with(this)
            addFeature(multiStatusFeature)
        }
        if (enableTitleBar()) {
            titleBarFeature.with(this) {
                onTitleBarInited(it)
            }
            addFeature(titleBarFeature)
        }
    }

    override fun enableImmersionBar(): Boolean {
        if (self() is Activity) {
            return true
        } else if (self() is Fragment) {
            return false
        }
        return false
    }

    override fun enableTitleBar(): Boolean {
        return self() is BaseActivity
    }

    open fun onTitleBarInited(titleBar: CommonTitleBar) {
    }
}
